package previous.Test_0207;

/**
 * Created with Intellij IDEA
 * Description:
 * User: 星辰
 */
class TreeNode {
      int val;
      TreeNode left;
      TreeNode right;
      TreeNode() {}
      TreeNode(int val) { this.val = val; }
      TreeNode(int val, TreeNode left, TreeNode right) {
          this.val = val;
          this.left = left;
          this.right = right;
      }
  }
public class Solution {
    //二叉搜索树中第K小的元素
    int count=0;
    int ret=Integer.MIN_VALUE;
    public int kthSmallest(TreeNode root, int k) {
        count=k;
        dfs(root);
        return ret;
    }
    public void dfs(TreeNode root){
        if(root==null || count==0){
            return ;
        }
        dfs(root.left);
        count--;
        if(count==0){
            ret=root.val;
        }

        if(count==0){
            return ;
        }
       dfs(root.right);
    }
    //二叉树的所有路径
    
}
